package Test;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

//鼠标监听
public class MyJfram2 extends JFrame implements MouseListener{
    JButton jb = new JButton("点");
    public MyJfram2(){
        this.setSize(600,550);
        this.setTitle("拼图");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setLayout(null);



        jb.setBounds(0,0,100,50);

        //绑定鼠标监听
        jb.addMouseListener(this);
        this.getContentPane().add(jb);

        this.setVisible(true);
    }

    //按下范围内的按键不松，会反复调用方法
    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("点击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("滑入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("滑出");
    }
}
